package com.simon.resourcestatistics.util;

import java.util.ArrayList;
import java.util.List;

import com.simon.resourcestatistics.model.Statistics;
import com.simon.resourcestatistics.vo.RoomChartVO;

public class ChartUtil {
    
//标准折线图
public static List<RoomChartVO> getChart(List<Statistics> list){
    List<RoomChartVO> voList = new ArrayList<RoomChartVO>();
    for(Statistics statistics:list){
        boolean flag = true;//flag为true表示改资源室不在voList中
        //遍历voList看看下一条数据的资源室是否已存在
        for(RoomChartVO vo :voList){
            if(vo.getName().equals(statistics.getReadRoom().getName())){//如果voList中已存在资源室
                flag = false;
                vo.getData().add(statistics.getNum());//添加数据
                break;
            }
        }
        if(flag){//若voList中没有，则新建一个vo对象
            RoomChartVO vo = new RoomChartVO();
            vo.setName(statistics.getReadRoom().getName());
            List<Integer> numList = new ArrayList<Integer>();
            numList.add(statistics.getNum());
            vo.setData(numList);
            voList.add(vo);
        }
    }
    return voList;
 }
}